package com.future.hair.server.config.result;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHander {
    @ExceptionHandler(value = Exception.class)
    public CommonResult handlerException(Exception e){
        if (e instanceof DataAddException){
//            log.error("【全局异常拦截】DataAddException: 请求方法 {}, 请求路径 {}",((DataAddException)e).getCode(),((DataAddException)e).getMessage());
            return CommonResult.failed(ResultCode.DATA_ADD_ERROR);
        }else if (e instanceof DataMatchException){
//            log.error("【全局异常拦截】DataMatchException: 请求方法 {}, 请求路径 {}",((DataMatchException)e).getCode(),((DataMatchException)e).getMessage());
            return CommonResult.failed(ResultCode.USERNAME_OR_PASSWORD_ERROR);
        } else {
//            log.error("服务器内部出错{}",e);
            System.out.println(e);
            return CommonResult.failed(ResultCode.FAILED);
        }
    }
}
